﻿/*
 * Сделано в SharpDevelop.
 * Пользователь: max
 * Дата: 09/01/2012
 * Время: 13:50
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using System.Windows;
using System.Windows.Input;
using jellybird.core;

namespace jellybird
{
	/// <summary>
	/// Description of Commands.
	/// </summary>
	public static class MyCommands
	{
		static MyCommands()
		{
			m_ProcessGapCommand=new RoutedUICommand
				("Gap detected",
				 "ProcessGap",
				 typeof(MyCommands));
			
			m_AddAccountCommand=new RoutedUICommand
				("Add account",
				 "AddAccount",
				 typeof(MyCommands));
			
			toggleHomeTimeline=new RoutedUICommand
				("Home",
				 "HomeTimeline",
				 typeof(MyCommands));
			
			toggleMentionsTimeline=new RoutedUICommand
				("Mentions",
				 "MentionsTimeline",
				 typeof(MyCommands));
			
			toggleUserTimeline=new RoutedUICommand
				("Tweets",
				 "UserTimeline",
				 typeof(MyCommands));
			
			credentials_edit=new RoutedUICommand
				("Credentials",
				 "Credentials",
				 typeof(MyCommands));
			
			cancel_dialog=new RoutedUICommand
				("Cancel",
				 "Cancel",
				 typeof(MyCommands),
				 new InputGestureCollection(){new KeyGesture(Key.Escape)});
			
			ok_dialog=new RoutedUICommand
				("OK",
				 "Ok",
				 typeof(MyCommands));
			
			navigate_url=new RoutedUICommand
				("Navigate",
				 "Navigate",
				 typeof(MyCommands));
		}
		
		private static RoutedUICommand m_ProcessGapCommand;
		public static RoutedUICommand ProcessGapCommand
		{
			get{return m_ProcessGapCommand;}
		}
		
		private static RoutedUICommand m_AddAccountCommand;
		public static RoutedUICommand AddAccountCommand
		{
			get{return m_AddAccountCommand;}
		}
		
		static RoutedUICommand toggleHomeTimeline;
		public static RoutedUICommand ToggleHomeTimeline {
			get { return toggleHomeTimeline; }
		}
		
		static RoutedUICommand toggleMentionsTimeline;
		public static RoutedUICommand ToggleMentionsTimeline {
			get { return toggleMentionsTimeline; }
		}
		
		static RoutedUICommand toggleUserTimeline;
		public static RoutedUICommand ToggleUserTimeline {
			get { return toggleUserTimeline; }
		}
		
		private static RoutedUICommand credentials_edit;
		public static RoutedUICommand CredentialsEdit
		{
			get{return credentials_edit;}
		}
		
		private static RoutedUICommand cancel_dialog;
		public static RoutedUICommand CancelDialog
		{
			get{return cancel_dialog;}
		}
		
		private static RoutedUICommand ok_dialog;
		public static RoutedUICommand OkDialog
		{
			get{return ok_dialog;}
		}
		
		private static RoutedUICommand navigate_url;
		public static RoutedUICommand NavigateUrl
		{
			get{return navigate_url;}
		}
	}
	
	public static class MyHandlers
	{
		internal static void AddAccountDialogStart(object sender, ExecutedRoutedEventArgs e)
		{
			#if DEBUG
			Program.JellybirdApplication.DebugMessage("Add account command invoked");
			#endif
			
			MainWindow main_window=(MainWindow)Program.JellybirdApplication.MainWindow;
			TwCredentials new_creds=new TwCredentials();
			main_window.ChildWindowCredentials.DataContext=new_creds;
			main_window.ChildWindowCredentials.Show();
			
			
		}
		
		internal static void CredentialsDialogReturns(object sender, ExecutedRoutedEventArgs e)
		{
			TwCredentials creds=(TwCredentials)((FrameworkElement)sender).DataContext;
			
			TwAccount new_account=new TwAccount()
			{
				Credentials=creds
			};
			try
			{
				if(new_account.Verify())
				{
					Program.AccountManager.Add(new_account);
				}
			}
			catch(Exception ex)
			{
				#if DEBUG
				Program.JellybirdApplication.DebugMessage(string.Format("Exception: {0}",ex.Message));
				#endif
			}
			
			
			#if DEBUG
//			Program.JellybirdApplication.DebugMessage(string.Format("Credentials dialog returns. Consumer key={0}",creds.ConsumerKey));
			#endif
		}
	}
}
